package utility;
import java.awt.*;
import java.awt.geom.Rectangle2D;

import button.*;

public class Utility {
	private static int x;
	private static int y;
	private static int stringLength;
	private static int stringHeight;
	private static FontMetrics fontMetrics;
	private static Rectangle2D r2d;
	private static Point buttonCenterPoint;
	public static Graphics2D programGraphics;
	public static Point calculateStringLocationOneLine(MyButton b, Graphics g){
		fontMetrics = g.getFontMetrics();
		r2d = fontMetrics.getStringBounds(b.getMsg(), g);
		buttonCenterPoint = getButtonCenterPoint(b);
		if(b.getWidth() < r2d.getWidth()){
			System.out.println("String size larger than button width!");
			x = b.getX();
		}else{
			x = b.getX() + (int)(buttonCenterPoint.getX() - r2d.getWidth() / 2);
		}
		if(b.getHeight() < r2d.getHeight()){
			System.out.println("String height larger than button height!");
			y = b.getY() + fontMetrics.getHeight();
		}else{
			//y = b.getY() + (int)(buttonCenterPoint.getY() - r2d.getHeight() / 2);
			y = b.getY() + fontMetrics.getAscent() + (int)r2d.getHeight() / 2;
		}
		return new Point(x, y);
	}
	
	public void fotmatingString(String msg, int width){
		int x = programGraphics.getFontMetrics().stringWidth(msg);
		if(x > width){
			while((x = x -width) > 0){
				
			}
		}
	}
	
	public static void programGraphics(Graphics2D g2d){
		programGraphics = g2d;
	}
	private static Point getButtonCenterPoint(MyButton b){
		return new Point(b.getWidth()/2, b.getHeight() / 2 );
	}
	
	
	
}
